package com.captjack.micro.task.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.config.JobCoreConfiguration;
import org.springframework.stereotype.Component;

/**
 * @author Capt Jack
 * @date 2018/6/1
 */
@Component(value = "secondJob")
public class SecondJob implements SimpleJobSupport {

    @Override
    public void execute(ShardingContext shardingContext) {
        System.out.println(String.format("------Thread ID: %s, 任务总片数: %s, " +
                        "当前分片项: %s.当前参数: %s," +
                        "当前任务名称: %s.当前任务参数: %s",
                Thread.currentThread().getId(),
                shardingContext.getShardingTotalCount(),
                shardingContext.getShardingItem(),
                shardingContext.getShardingParameter(),
                shardingContext.getJobName(),
                shardingContext.getJobParameter()
        ));
    }

    @Override
    public JobCoreConfiguration getJobCoreConfiguration() {
        return JobCoreConfiguration.newBuilder(this.getClass().getName(), "0 0/1 * * * ?", 1)
                .shardingItemParameters("0=parameter0")
                // 设置分片策略
                .jobProperties("jobShardingStrategyClass", "com.dangdang.ddframe.job.plugin.sharding.strategy.AverageAllocationJobShardingStrategy")
                .build();
    }

}
